/***************************************************************************
*   Copyright (C) 2010-2011 by swkyer <swkyer@gmail.com>                  *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU General Public License as published by  *
*   the Free Software Foundation; either version 2 of the License, or     *
*   (at your option) any later version.                                   *
*                                                                         *
*   This program is distributed in the hope that it will be useful,       *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU General Public License for more details.                          *
*                                                                         *
*   You should have received a copy of the GNU General Public License     *
*   along with this program; if not, write to the                         *
*   Free Software Foundation, Inc.,                                       *
*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/
#ifndef __JLINK_H__
#define __JLINK_H__

#include "../JlinkUSB/JlinkUSB.h"
#include "../JlinkUSB/JlinkProtocol.h"
#include "Tap.h"


typedef struct __jlink
{
    jtagdev_cfg_t cfg;

    tap_state_t state;

    jlink_usb_t *usbdev;

    jlink_caps_t caps;
    jlink_speed_t speed;
    jlink_state_t pinstate;
    jlink_hwinfo_t hwinfo;
    jlink_jtag_acc_t jacc;
    jlink_unknow_09_t u09;
} jlink_t;


jlink_t *jlink_open(jtagdev_cfg_t *pcfg);
int jlink_close(jlink_t *pjlink);
jlink_t *jlink_reinit(jlink_t *pjlink);

int jlink_is_target_connect(jlink_t *pjlink);

int jlink_trst_activate(jlink_t *pjlink);
int jlink_trst_deactivate(jlink_t *pjlink);
int jlink_rst_activate(jlink_t *pjlink);
int jlink_rst_deactivate(jlink_t *pjlink);

int jlink_tap_reset(jlink_t *pjlink, int use_trst);
int jlink_runtest_idle(jlink_t *pjlink);

tap_state_t jlink_get_tap_state(jlink_t *pjlink);
int jlink_tap_moveto(jlink_t *pjlink, tap_state_t dest);

int jlink_data(jlink_t *pjlink, ubase_t data_out, ubase_t *pdatain);
int jlink_instruction(jlink_t *pjlink, ubase_t ir_out, ubase_t *pirin);


#endif /* end of __JLINK_H__ */
